<template>
<div class="product-add">
    <!--form表单-->
    <el-form size="small" ref="form" :model="form" label-width="200px">
      <!--新增退货地址-->
      <div class="common-form">{{$t('setting.add_return_address')}}</div>
      <el-form-item
        :label="$t('setting.recipient_name')"
        prop="name"
        :rules="[{  required: true,  message: ' '}]"
      >
        <el-input
          type="text"
          v-model="form.name"
          class="max-w460"
          prop="name"
        ></el-input>
      </el-form-item>
      <el-form-item
        :label="$t('setting.contact_number')"
        prop="phone"
        :rules="[{  required: true,  message: ' '}]"
      >
        <el-input type="text" v-model="form.phone" class="max-w460"></el-input>
      </el-form-item>
      <el-form-item
        :label="$t('setting.detailed_address')"
        prop="detail"
        :rules="[{  required: true,  message: ' '}]"
      >
        <el-input type="text" v-model="form.detail" class="max-w460"></el-input>
      </el-form-item>
      <el-form-item :label="$t('setting.sort_order')">
        <el-input v-model="form.sort" type="number" class="max-w460"></el-input>
        <div class="tips">{{$t('setting.sort_order_tip')}}</div>
      </el-form-item>

      <!--提交-->
      <div class="common-button-wrapper">
        <el-button
          size="small"
          type="primary"
          @click="onSubmit()"
          :loading="loading"
          >{{$t('setting.submit_button')}}</el-button
        >
      </div>
    </el-form>
  </div>
</template>

<script>
import SettingApi from "@/api/setting.js";
export default {
  data() {
    return {
      loading: false,
      /*切换菜单*/
      // activeIndex: '1',
      /*form表单数据*/
      form: {
        name: "",
        phone: "",
        detail: "",
        sort: 1
      }
    };
  },
  created() {},
  methods: {
    //提交表单
    onSubmit() {
      let self = this;
      let form = self.form;
      self.$refs.form.validate(valid => {
        if (valid) {
          self.loading = true;
          SettingApi.addAddress(form, true).then(data => {
            self.loading = false;
            ElMessage({
              message: $t("setting.add_success_message"),
              type: "success"
            });
            self.$router.push("/setting/address/index");
          }).catch(error => {
            self.loading = false;
          });
        }
      });
    }
  }
};
</script>

<style>
.tips {
  color: #ccc;
}
</style>

